package com.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.user.dao.restaurant.QueryPageRestaurant;
import com.user.dao.restaurant.RestaurantRecommend;
import com.user.domain.Restaurant;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author YU
 * @Description 针对表【restaurant】的数据库操作Mapper
 * @Date 2024-02-05 17:55:05
 * @Entity .domain.com.user.domain.Restaurant
 */
public interface RestaurantMapper extends BaseMapper<Restaurant> {


    /**
     * 根据用户id查询餐厅
     *
     * @param id 用户id
     */
    @Select("select id from restaurant where master = #{id}")
    Integer selectByMaster(Integer id);

    IPage<Restaurant> selectRestaurant(@Param("restaurant") QueryPageRestaurant restaurant, @Param("mapPage") Page<Restaurant> mapPage);

    long selectRestaurantCount(@Param("restaurant") QueryPageRestaurant restaurant);


    /**
     * 根据餐厅id查询餐厅管理员id
     *
     * @param restaurantId 餐厅id
     */
    @Select("select master from restaurant where id = #{restaurantId}")
    Integer selectMasterIdById(Integer restaurantId);

    /**
     * 更新餐厅评分旧评分+新评分/2
     *
     * @param restaurantId    餐厅id
     * @param restaurantScore 餐厅评分
     */
    @Select("update restaurant set score = (score + #{restaurantScore})/2 where id = #{restaurantId}")
    void updateRestaurantScore(Integer restaurantId, BigDecimal restaurantScore);

    IPage<Restaurant> selectRestaurants(@Param("restaurant") QueryPageRestaurant restaurant, @Param("mapPage") Page<Restaurant> mapPage);

    @Select("select name from restaurant where id = #{v}")
    String selectRestaurantNameByid(Integer v);

    List<RestaurantRecommend> selectRestaurantRecommend();

}




